package thread;

import java.util.Scanner;

public class Demo25 {
    /*private static Object lock1 = new Object();
    private static Object lock2 = new Object();
    private static Object lock3 = new Object();*/


    public static void main(String[] args) throws InterruptedException {
        for (int i = 0; i < 10; i++) {
            Object lock1 = new Object();
            Object lock2 = new Object();

            Thread t3 = new Thread(() -> {
                synchronized (lock2) {
                    try {
                        lock2.wait();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    System.out.print("C\n");
                }
            });

            Thread t2 = new Thread(() -> {
                synchronized (lock1) {
                    try {
                        lock1.wait();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    System.out.print("B");
                }
                synchronized (lock2) {
                    lock2.notify();
                }
            });

            Thread t1 = new Thread(() -> {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                synchronized (lock1) {
                    System.out.print("A");
                    lock1.notify();
                }
            });

            // 按顺序启动线程
            t3.start();
            t2.start();
            t1.start();

            // 等待当前批次完成（可选）
            t1.join();
            t2.join();
            t3.join();
        }
    }

}
